/*
*******************************************************************************
* ansi c source code
* file name:
*	bit-rev.c
* abstract:
*	complete the bit reverse of the input
* author:Fangming He
*******************************************************************************
*/


/*
*******************************************************************************
*                               include files
*******************************************************************************
*/

#include <stdio.h>
#include "globaldef.h"


/*
*******************************************************************************
*                            function definition
*******************************************************************************
*/
/*
******************************************************************************* 
* description:
*	complete the bit reverse of the input
* input:
*	input  : the original data needed being bit reversed
*	length : the length of the input data
* author:
*	guo liang       2006-05-04
*******************************************************************************
*/

void bit_rev (struct Complex * input, int length )
{
	int i;              /* the sequence number of the original data */      
	int j;              /* the sequence number of the bit reversed data */
	int k;               
	struct Complex temp;
	j=0;
	for ( i=1; i < (length-1); i++)
	{
		k = length >> 1;   /* calculate the next sequence number of the bit reverse data */
		while ( k <= j)
		{
			j-=k;
			k>>=1;
		}
		j += k;             
		if ( i < j)
		{
			temp = input[j];
			input[j]= input[i];
			input[i]= temp;
		}
	}
}
		

/*
*******************************************************************************
* ansi c source code
* file name:
*	Mul-complex.c
* abstract:
*	to complete the multiply for the complex 
* author:
*	guo liang       2006-05-04
* revision history:
*	guo liang       2006-05-04	original version
*******************************************************************************
*/

struct Complex Mul_complex ( struct Complex data1,struct Complex data2)
{
	struct Complex result;
	double temp;
	temp = data1.real * data2.real - data1.imag * data2.imag;
	result.real = temp;
	temp = data1.imag * data2.real + data1.real * data2.imag;
	result.imag = temp;
	return result;
}
